<template>
  <div style="font-size: 25px">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo fx"
      mode="horizontal"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      @select="handleSelect"
    >
      <el-menu-item index="1">首页</el-menu-item>
      <el-menu-item index="2">酒店</el-menu-item>
      <el-menu-item index="3">景区</el-menu-item>
      <el-menu-item index="4">套餐</el-menu-item>
      <el-menu-item index="5" style="display: flex; align-items: center">
        <div class="img">
          <img :src="users.userImg" alt="" />
        </div>
        <p style="font-size: 20px; margin-left: 10px; color: white">
          {{ users.userName }}
        </p>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "navmenu",
  data() {
    return {
      activeIndex: "1",
      users: { userName: "", userImg: "" },
    };
  },
  methods: {
    //获取用户名
    getUserInfo() {
      // console.log(this.users.userId);
      this.$api.usersApi
        .queryUserById({ userId: this.users.userId })
        .then((res) => {
          this.users.userName = res.data.data.userName;
          // console.log(this.users.userName);
        });
    },
    //获取用户头像
    getUserImg() {
      this.$api.picturesApi
        .getUserImg({ userId: this.users.userId })
        .then((res) => {
          this.users.userImg = res.data.data;
          // console.log(this.users.userImg);
        });
    },
    // element ui
    handleSelect(key, keyPath) {
      if (key == 1) this.$router.push({ name: "home" });
      else if (key == 2) this.$router.push({ name: "hotel" });
      else if (key == 3) this.$router.push({ name: "landmark" });
      else if (key == 4) this.$router.push({ name: "package" });
      else if (key == 5) this.$router.push({ name: "user" });
    },
  },
  mounted() {
    //获取useruserId
    this.users.userId = localStorage.getItem("USERID");
    //获取用户名
    this.getUserInfo();
    //获取用户头像
    this.getUserImg();
  },
};
</script>

<style>
.fx {
  display: flex;
  justify-content: space-around;
}

.img {
  display: inline-block;
  width: 50px;
  height: auto;
  vertical-align: middle;
  display: flex;
  align-items: center;
}

.img img {
  width: 100%;
  height: auto;
}
</style>
